package com.itlong.cloud.tapd.util;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * <des>
 *
 * <des>
 *
 * @create Date 2021-09-08
 **/
public class GetTime {
    static String sevenDaysAgo;
    static String sevenDaysAfter;
    static String nineDaysAgo;
    static String now;
    static String lastDayOfLastMonth;
    static String firstDayOfLastMonth;
    static Integer lastMonth;
    static String firstDayOfLast6Month;
    static Calendar calendar;

    public static String getSevenDaysAgo(){
        calendar = Calendar.getInstance();
        calendar.setTime(new Date());
        calendar.add(Calendar.DATE, -7);
        sevenDaysAgo = new SimpleDateFormat("yyyy-MM-dd").format(calendar.getTime());
        return sevenDaysAgo;
    }

    public static String getSevenDaysAfter(){
        calendar = Calendar.getInstance();
        calendar.setTime(new Date());
        calendar.add(Calendar.DATE, 7);
        sevenDaysAfter = new SimpleDateFormat("yyyy-MM-dd").format(calendar.getTime());
        return sevenDaysAfter;
    }

    public static String getNineDaysAgo(){
        calendar = Calendar.getInstance();
        calendar.setTime(new Date());
        calendar.add(Calendar.DATE, -9);
        nineDaysAgo = new SimpleDateFormat("yyyy-MM-dd").format(calendar.getTime());
        return nineDaysAgo;
    }

    public static String getNow(){
        now = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
        return now;
    }

    public static String getFirstDayOfLastMonth(){
        calendar = Calendar.getInstance();
        SimpleDateFormat formatTemp = new SimpleDateFormat("yyyy-MM-dd");
        calendar.add(Calendar.MONTH,-1);
        calendar.set(Calendar.DAY_OF_MONTH, 1);
        firstDayOfLastMonth = formatTemp.format(calendar.getTime());
        return firstDayOfLastMonth;
    }

    public static String getLastDayOfLastMonth(){
        calendar = Calendar.getInstance();
        SimpleDateFormat formatTemp = new SimpleDateFormat("yyyy-MM-dd");
        calendar.add(Calendar.MONTH,-1);
        calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMaximum(Calendar.DAY_OF_MONTH));
        lastDayOfLastMonth = formatTemp.format(calendar.getTime());
        return lastDayOfLastMonth;
    }

    public static Integer getLastMonth(){
        calendar = Calendar.getInstance();
        SimpleDateFormat formatTemp = new SimpleDateFormat("yyyy-MM-dd");
        calendar.add(Calendar.MONTH,-1);
        lastMonth = calendar.getTime().getMonth()+1;
        return lastMonth;
    }

    public static String getFirstDayOfLast6Month(){
        calendar = Calendar.getInstance();
        SimpleDateFormat formatTemp = new SimpleDateFormat("yyyy-MM-dd");
        calendar.add(Calendar.MONTH,-6);
        calendar.set(Calendar.DAY_OF_MONTH, 1);
        firstDayOfLast6Month = formatTemp.format(calendar.getTime());
        return firstDayOfLast6Month;
    }

}